package com.rran.study.designpattern.factory.singleton.lazy;

/**
 * @author yy
 * @Type SyncLazySingletion.java
 * @Desc 加锁版本，简单懒汉上的优化
 * @date 2020/7/23 10:07
 */
public class SyncLazySingleton {
    private static SyncLazySingleton instance;

    private SyncLazySingleton() {
    }
    //加上锁，只能有一个线程进入到getinstance方法
    //复杂场景效率很低
    public static synchronized SyncLazySingleton getInstance() {
        if (instance == null) {
            instance = new SyncLazySingleton();
        }
        return instance;
    }

}
